<?php
global $_W,$_GPC;
$pindex = max(intval($_GPC['page']), 1);
$psize = 10;
$uid = $_W['fans']['uid'];
if (empty($uid)) MSG('请先关注公众号');
$limit = "limit " . (($pindex -1) * $psize).','. $psize;
$list = getall("select uid,credit1,nickname,avatar from ".tablename('mc_members')." where uniacid='{$_W['uniacid']}' order by credit1 desc,uid {$limit}");

foreach ($list as $k=> $value) {
	$list[$k]['credit1'] = intval($value['credit1']);
	$list[$k]['avatar'] = str_replace('132132', '132', $value['avatar']);
}

if ($pindex >= 2){
	if ($list) resp(array('status'=>1,'list'=>$list));
	else resp(array('status'=>0));
}

foreach ($list as $k => $value) {
	if ($uid == $value['uid']){
		$value['rank'] = $k+1;
		$mem = $value;
		break;
	}
}

if (!$mem){ //自己在十以后 要统计
	$mem = get("select credit1,nickname,avatar from ".tablename('mc_members')." where uid='{$uid}'");
	$mem['rank'] = col("select count(1) from ".tablename('mc_members')." where uniacid='{$_W['uniacid']}' and credit1>='{$score}' order by credit1 desc,uid");
}
$mem['credit1'] = intval($mem['credit1']);
$mem['avatar'] = str_replace('132132', '132', $mem['avatar']);
$settings = get("select ranks from ".tb('scorerank')." where uniacid='{$_W['uniacid']}'");
$set = unserialize($settings['ranks']);
$adv = $set['adv'];
include $this->template('scorerank');